package edu.tgc.entity.system;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class SysPosition extends BaseAuditableEntity {

    private static final long serialVersionUID = 6797725857127400519L;
    @JsonIgnore
    protected Set<SysDept> depts = new HashSet<>();
    protected String description;
    @JsonIgnore
    protected Set<SysDuty> duties = new HashSet<>();
    protected Boolean enabled = true;
    protected String name;
    protected Integer sort = 1;
    @JsonIgnore
    protected Set<SysUserDept> userDepts = new HashSet<>();

    public SysPosition() {
    }

    public SysPosition(UUID id) {
        this.id = id;
    }

    @ManyToMany
    @JoinTable(name = "sys_dept_position", joinColumns = @JoinColumn(name = "position_id"), inverseJoinColumns = @JoinColumn(name = "dept_id"))
    public Set<SysDept> getDepts() {
        return this.depts;
    }

    @Column(name = "description", length = 255)
    public String getDescription() {
        return this.description;
    }

    @ManyToMany
    @JoinTable(name = "sys_position_duty", joinColumns = @JoinColumn(name = "position_id"), inverseJoinColumns = @JoinColumn(name = "duty_id"))
    public Set<SysDuty> getDuties() {
        return this.duties;
    }

    @Column(name = "enabled")
    public Boolean getEnabled() {
        return this.enabled;
    }

    @Column(name = "name", length = 31)
    public String getName() {
        return this.name;
    }

    @Column(name = "sort")
    public Integer getSort() {
        return this.sort;
    }

    @ElementCollection
    @CollectionTable(name = "sys_user_position", joinColumns = @JoinColumn(name = "position_id"))
    public Set<SysUserDept> getUserDepts() {
        return this.userDepts;
    }

    public void setDepts(Set<SysDept> depts) {
        this.depts = depts;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setDuties(Set<SysDuty> duties) {
        this.duties = duties;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public void setUserDepts(Set<SysUserDept> userDepts) {
        this.userDepts = userDepts;
    }
}
